package com.haieros.www.purerunshowsystem.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.haieros.www.purerunshowsystem.bean.UpdateInfo;
import com.haieros.www.purerunshowsystem.socket.SocketUtils;

import java.util.Date;

/**
 * Created by Administrator on 2017\12\21 0021.
 */

public class DataChangeReceiver extends BroadcastReceiver {

    private SocketUtils socketUtils;//socket相关，用于发送socket数据
    Date date;
    int i = 0;

    public DataChangeReceiver(SocketUtils socketUtils) {
        this.socketUtils = socketUtils;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("TAG","时间变化"+i++);
        if (date != null&&(date.getMinutes()==(new Date().getMinutes()))){
            Log.i("=====",date.getMinutes()+"======同一时间，不在重复请求！"+new Date().getMinutes());
            return;
        }
            date=new Date();
//        if(date.getHours()==20)
//        {
//           if(date.getMinutes()==20)
//           {
//            if(i==0)
//            {
//                Toast.makeText(context,"跳转臭氧",Toast.LENGTH_SHORT).show();
//                i++;
//                Log.e("TAG","跳转臭氧页面"+date.getMinutes()+"--"+date.getHours());
//
//                Intent  intent2 = new Intent(context,LaunchEquipmenActivity.class);
//                context.startActivity(intent2);
//            }
//
//           }
//        }
        //每天0点到5点，每隔半小时轮询一次，查看是否有新版本更新
//        if (0 <= date.getHours() && date.getHours() <= 5) {
//            if (date.getMinutes() == 0 || date.getMinutes() == 30) {
                socketUtils.sendUpdateInfo(new UpdateInfo("haier", ""));
//            }
//        }
        Log.i("TAG", "时间变化" + date.getMinutes() + "--" + date.getHours());
    }
}
